package thread.state.intercept;

public class ThreadSleepInterruptTest {
    public static void main(String[] args) {
        Thread thread = new Thread() {
            @Override
            public void run() {
                super.run();

                System.out.println("Thread " + Thread.currentThread().getName() + "time: " + System.currentTimeMillis() + ", isInterrupted = " + isInterrupted());

                try {
                    Thread.sleep(4000);
                } catch (InterruptedException e) {
                    e.printStackTrace();

                    System.out.println("Thread " + Thread.currentThread().getName() + "time: " + System.currentTimeMillis() + ", in catch interruptedException = " + e.getMessage());
                    /**
                     * 这里的isInterrupted()仍旧返回false
                     * */
                    System.out.println("Thread " + Thread.currentThread().getName() + "time: " + System.currentTimeMillis() + ", in catch interruption isInterrupted = " + isInterrupted());
                }

                System.out.println("Thread " + Thread.currentThread().getName() + "time: " + System.currentTimeMillis() + ", isInterrupted = " + isInterrupted());
            }
        };

        thread.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        thread.interrupt();
    }
}